package com.bestcem.xm.member.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bestcem.xm.member.entity.mysql.ExportRecordEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 导出记录mapper
 * @author dc.wang <dc.wang@idiaoyan.com>
 * @version V1.0
 * @date 2021/9/22 16:08
 */
@Mapper
public interface ExportRecordMapper extends BaseMapper<ExportRecordEntity> {
    /**
     * 更新导出记录状态、错误信息
     * @param recordDo 导出记录信息
     * @return 更新列数
     * @author dc.wang <dc.wang@idiaoyan.com>
     * @date 2021/9/22
     */
    Integer updateStatusById(@Param("record") ExportRecordEntity recordDo);

    /**
     * 创建导出记录
     *
     * @param toEntity
     */
    void saveRecord(ExportRecordEntity toEntity);

    /**
     * 批量创建导出记录
     *
     * @param entities 导出记录集合
     */
    void batchCreate(List<ExportRecordEntity> entities);

    /**
     * 更新
     *
     * @param toEntity
     */
    void updateStatusAndFile(ExportRecordEntity toEntity);

    /**
     * 统计
     *
     * @param orgId
     * @param opUserId
     * @param memberType
     * @return
     */
    long countByUser(@Param("orgId") String orgId, @Param("opUserId") String opUserId, @Param("memberType") int memberType);

    /**
     * 获取 改操作人下的数据
     *
     * @param orgId
     * @param opUserId
     * @param memberType
     * @param skip
     * @param limit
     * @return
     */
    List<ExportRecordEntity> listByUser(@Param("orgId") String orgId,
                                        @Param("opUserId") String opUserId,
                                        @Param("memberType") int memberType,
                                        @Param("skip") long skip,
                                        @Param("limit") int limit);

    /**
     * 根据 id 和组织id 获取数据
     *
     * @param id
     * @param orgId
     * @return
     */
    ExportRecordEntity findOneByIdAndOrgId(@Param("id") String id, @Param("orgId") String orgId);

    /**
     * 批量删除记录
     *
     * @param orgId
     * @param ids
     */
    void batchDeleteByIds(@Param("orgId") String orgId, @Param("list") List<String> ids);

    void updateStatusAndMsgById(@Param("id") String id, @Param("status") int status, @Param("msg") String msg);

    void batchSave(@Param("list") List<ExportRecordEntity> entities);
}
